/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.dusty.fs.filesystem.data;

import java.io.IOException;
import java.io.RandomAccessFile;
import static ru.dusty.fs.filesystem.utils.PrimitiveSizes.sizeof;
import ru.dusty.fs.filesystem.utils.Utils;

/**
 *
 * @author Dusty
 */
public class SuperBlock extends MetaData {
    
    private int blockSize;
    
    private int blockCount;
    
    public SuperBlock() {
        blockSize = Utils.BLOCK_MIN_SIZE;
        blockCount = Utils.BLOCK_MIN_COUNT;
        setType(BlockType.FOLDER);
    }

    public int getBlockCount() {
        return blockCount;
    }

    public int getBlockSize() {
        return blockSize;
    }

    public void setBlockCount(int blockCount) {
        this.blockCount = blockCount;
    }

    public void setBlockSize(int blockSize) {
        this.blockSize = blockSize;
    }
    
    @Override
    public void write(RandomAccessFile raf) throws IOException {
        super.write(raf);
        
        raf.writeInt(blockSize);
        
        raf.writeInt(blockCount);
    }
    
    @Override
    public void read(RandomAccessFile raf) throws IOException {
        super.read(raf);
        
        blockSize = raf.readInt();
        
        blockCount = raf.readInt();
    }
    
    @Override
    public int getMetaDataSize() {
        return super.getMetaDataSize() + sizeof(blockSize) + 
                sizeof(blockCount);
    }
}
